package com.example.mybackend.mapper;

import com.example.mybackend.entity.administrator;
import com.example.mybackend.entity.travelogue;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface travelogueMapper {
    @Select("SELECT * FROM travelogue WHERE deleted_tag = 0")
   List<travelogue> queryAll();

    @Select("SELECT * FROM travelogue WHERE deleted_tag = 1")
    List<travelogue> queryDeleted();

    @Select("SELECT * FROM travelogue WHERE status = 0 AND deleted_tag = 0")
    List<travelogue> queryStatus0();

    @Select("SELECT * FROM travelogue WHERE status = 1 AND deleted_tag = 0")
    List<travelogue> queryStatus1();

    @Select("SELECT * FROM travelogue WHERE status = 2 AND deleted_tag = 0")
    List<travelogue> queryStatus2();

    @Update("UPDATE travelogue SET deleted_tag = 1 WHERE id =#{id}")
    Integer Delete(Integer id);

    @Update("UPDATE travelogue SET deleted_tag = 0, status = 0 ,reject_reason=NULL WHERE id =#{id} ")
    Integer Recover(Integer id);

    @Update("UPDATE travelogue SET status = 1 WHERE id =#{id}")
    Integer Pass(Integer id);

    @Update("UPDATE travelogue SET status = 2,reject_reason=#{reject_reason} WHERE id =#{id}")
    Integer Reject(travelogue Travelogue);

    @Select("SELECT * FROM travelogue WHERE content LIKE CONCAT('%', #{content}, '%')")
    List<travelogue> queryContentLike(String content);

 @Select("SELECT t.id, t.title, t.content, t.status, t.created_date, t.deleted_tag, t.reject_reason " +
         "FROM travelogue t " +
         "JOIN user u ON t.user_id = u.id " +
         "WHERE u.username LIKE CONCAT('%', #{username}, '%')")
 List<travelogue> queryUserLike(String username);
}
